import random
f=open("text1.txt",'w')
while True:
    i=random.randint(1,122)
    x=chr(i)
    if x.isupper() or x.islower() or x.isdigit() or x in ('\n','\r','*','&','^','$'):
        f.write(x)
    if f.tell()>10000:
        break
f.close()

f=open("D:text1.txt","rb")
a=f.read(100)
f.seek(-100,2)
b=f.read()
print('前一百字节字符：',a)
print('后一百字节字符：',b)
f.close()

with open('D:text1.txt','r') as file:
    up_zm=0
    low_zm=0
    digit=0
    for line in file:
        for char in line:
            if char.isdigit():
                digit+=1
            elif char.isupper():
                up_zm+=1
            elif char.islower():
                low_zm+=1
print(f'大写字母的次数为{up_zm}')
print(f'小写字母的次数为{low_zm}')
print(f'数字的次数为{digit}')


f=open('D:text2.txt','w')
for i in range(1,10):
    for j in range(1,10):
        f.write(f'{i}*{j}={i*j}\t' if i<j)
    f.write('\n')

f.close()



import openpyxl

# 创建一个新的Excel文件
wb = openpyxl.Workbook()
sheet = wb.active

# 在C5单元格写入字符串
sheet['C5'] = "我喜欢编程"

# 保存Excel文件
wb.save("test3.xlsx"